﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VCDIFF.Commands;

namespace VCDIFF.Create
{
    public class CreateWindow
    {
        IList<Window> WindowsList = new List<Window>();
        IList<Command> CommandsList = new List<Command>();
        Window Window { get; set; }
        UInt64 Win_Indicator = 0;
        UInt64 SourceLength;

        public CreateWindow(Int64 sourceLength, IList<Command> commandsList)
        {
            SourceLength = Convert.ToUInt64(sourceLength);
            CommandsList = commandsList;
            Initialize();
        }

        public void Initialize()
        {
            InitializeWindow();
            InitializeCommands();
            InitializeDeltaEncodingLength();
            InitializeTargetWindowSize();
        }

        public void InitializeWindow()
        {
            Win_Indicator++;
            Window = new Window();
            Window.WinIndicator = Convert.ToByte(Win_Indicator);
            Window.SourceSegmentSize = SourceLength;
            Window.SourceSegmentPosition = 0;
            Window.DeltaEncodingLength = 0;
            Window.TargetWindowSize = 0;
            Window.DeltaIndicator = 0;
            Window.AddAndRunDataLength = 0;
            Window.InstructionsAndSizesLength = 0;
            Window.CopyAddressesLength = 0;
            Window.AddAndRunDataSection = new byte[0];
            Window.InstructionsAndSizesSection = new byte[0];
            Window.CopyAddressesSection = new byte[0];
        }       

        public void InitializeCommands()
        {
            Window.InitializeCommands(CommandsList);
        }

        public void InitializeDeltaEncodingLength()
        {
            Window.InitializeDeltaEncodingLength();
        }

        public void InitializeTargetWindowSize()
        {
            Window.InitializeTargetWindowSize();
        }

        public byte[] GetWindowData()
        {
            return Window.GetWindowData();
        }

        public string GetWindowString()
        {
            return Window.GetWindowString();
        }
    }
}
